package com.zytlifeservice.service;

import com.zytlifeservice.domain.BaseIcon;
import com.zytlifeservice.exception.UserException;
import com.zytlifeservice.repository.BaseIconRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by MJS on 2017/5/8.
 */
@Service
public class BaseIconService {

    @Autowired
    BaseIconRepository baseIconRepository;

    @Autowired
    FileUploadService fileUploadService;

    public void add(BaseIcon bean) {
        if (baseIconRepository.save(bean) == null) {
            throw new UserException("添加失败", 103);
        }
    }

    public List<BaseIcon> queryAll(int[] type) {
//        return baseIconRepository.findAllByType(type);
        return baseIconRepository.findAllByTypeIn(type);
    }


    public void delete(long id) {
        BaseIcon one = baseIconRepository.findOne(id);
        fileUploadService.delete(one.getIcon());
        baseIconRepository.delete(id);
    }
}
